package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.StoreRoleMenu;
import com.dingreading.cloud.admin.entity.table.StoreRoleMenuTableDef;
import com.dingreading.cloud.admin.mapper.StoreRoleMenuMapper;
import com.dingreading.cloud.admin.service.StoreRoleMenuService;
import com.mybatisflex.core.query.QueryCondition;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-02-26
 */
@Service
public class StoreRoleMenuServiceImpl extends BaseServiceImpl<StoreRoleMenuMapper, StoreRoleMenu, StoreRoleMenuTableDef> implements StoreRoleMenuService {

    @Override
    protected StoreRoleMenuTableDef getTable() {
        return StoreRoleMenuTableDef.storeRoleMenu;
    }

    @Override
    public int dropByRoleId(Long roleId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.roleId.eq(roleId));

        return getMapper().deleteByCondition(condition);
    }

    @Override
    public List<StoreRoleMenu> getByRoleId(Long roleId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.roleId.eq(roleId));

        return getMapper().selectListByCondition(condition);
    }

    @Override
    public int dropByRoleIdNotMenuIds(Long roleId, List<Long> menuIds) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.roleId.eq(roleId))
                .and(table.menuId.notIn(menuIds));

        return getMapper().deleteByCondition(condition);
    }

    @Override
    public int dropByMenuId(Long menuId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.menuId.eq(menuId));

        return getMapper().deleteByCondition(condition);
    }
}
